package enchere.ihm.controlleur;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.swing.JFrame;

import enchere.EnchereRemote;
import enchere.Personne;
import enchere.ihm.vue.Accueil;
import enchere.ihm.vue.CompteCreation;
import enchere.ihm.vue.MenuEncheres;
import exception.PersonNotReferencedException;

public class AccueilControlleur {

	private static EnchereRemote enchereRemote;
	private static Personne personneConnectee;
	private JFrame accueil;
	
	public AccueilControlleur (JFrame accueil) throws NamingException{
		this.accueil = accueil;
		Context ctx = new InitialContext();
		enchereRemote = (EnchereRemote) ctx.lookup(EnchereRemote.class.getName());
	}
	
	public boolean identifier(String identifiant, String password) throws Exception {
		try {
			personneConnectee = enchereRemote.identifier(identifiant, password);
			accueil.setVisible(false);
			java.awt.EventQueue.invokeLater(new Runnable() {
				public void run() {
					new MenuEncheres().setVisible(true);
		        }
		     });
			return true;
		} catch (PersonNotReferencedException e) {
			return false;
		}
	}

	public void goToNewPersonneScreen() {
		accueil.setVisible(false);
		 /* Create and display the view */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CompteCreation().setVisible(true);
            }
        });
	}
	
}
